home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / bbs / dlmst251.zip / DOSWDW.ASM < prev    next >
Assembly Source File  |  1989-12-29  |  8KB  |  294 lines

  1. ;=====================================================================
  2. ;DOSWDW.ASM written by E. Dong to be used in Turbo C programming, and
  3. ;is based on EXECWIN.ASM originally written by Kim Kokkonen, TurboPower 
  4. ;Software (first in 10/88, then updated to 1.01 on 11/14/88) and 
  5. ;released to the public domain by K.K. K.K.'s 1.01 version added saving
  6. ;BP register since some int 10 BIOS handlers trash it.
  7. ;
  8. ;Version 2.0    12/29/89    Edward V. Dong
  9. ;This version (DOSWDW.ASM) ports EXECWIN.ASM from Turbo Pascal to Turbo
  10. ;C and adds optional pausing when the window fills up. If pausing is
  11. ;enabled, then any keystroke starts it again.
  12.  
  13.     name    doswdw
  14.  
  15. DOSWDW_TEXT    segment    byte public 'CODE'
  16. DGROUP    group    _DATA,_BSS
  17.     assume    cs:DOSWDW_TEXT,ds:DGROUP
  18. DOSWDW_TEXT    ends
  19. _DATA    segment word public 'DATA'
  20. _d@    label    byte
  21. _DATA    ends
  22. _BSS    segment word public 'BSS'
  23. _b@    label    byte
  24. _BSS    ends
  25.  
  26. _DATA    segment word public 'DATA'
  27.            extrn   _oldint21 : dword    ;Previous $21 vector
  28.            extrn   _wdwpause : byte     ;MORE filter: pause after each page
  29.            extrn   _wdwpos   : word     ;Cursor position in window
  30.            extrn   _wdwupr   : word     ;Top left corner of window
  31.            extrn   _wdwlwr   : word     ;   and bottom right corner.
  32.            extrn   _wdwattr  : byte     ;Attribute with which to
  33.                                         ;   display all characters.
  34. _DATA    ends
  35.  
  36. DOSWDW_TEXT    segment    byte public 'CODE'
  37. col    equ    (byte ptr 0)
  38. row    equ    (byte ptr 1)
  39.  
  40. ofst    equ    (word ptr 0)
  41. segm    equ    (word ptr 2)
  42.  
  43. ToDos      macro                        ;Transfer control to DOS
  44.            jmp  dword ptr Int21CS
  45.            endm
  46.  
  47. ToApp      macro                        ;Transfer control back to caller
  48.            clc                          ;Clear error flag
  49.            ret     2                    ;Return with flags intact
  50.            endm
  51.  
  52.            public  _setup21
  53.            public  _doswdw
  54.  
  55. Int21CS    dd      ?                    ;Old interrupt 21 in code segment
  56. rowcnt     db      ?                    ;Count of rows displayed so far
  57. rowlmt     db      ?                    ;Max rows to show for pausing
  58.  
  59. ;Set up dos window & check for pausing between pages
  60. ;Checks for single parameter (int) which is zero for no page
  61. ;pausing or is the number of rows to pause at.
  62.  
  63. _setup21   proc    far
  64.     push    bp
  65.     mov    bp,sp
  66.     mov    al,0            ;Initialize row counting
  67.     mov    rowcnt,al
  68.     mov    ax,word ptr [bp+6]    ;Limit specified?
  69.     mov    rowlmt,al        ;Save limit
  70.     les    ax,_oldint21        ;Save ints in code segment
  71.     mov    Int21CS.ofst,ax
  72.     mov    Int21CS.segm,es
  73.     mov    sp,bp
  74.     pop    bp
  75.     ret    
  76. _setup21   endp
  77.  
  78. ; Handle interrupt 21 to trap output calls
  79. _doswdw    proc    far
  80.     cmp    ah,2         ;Just get functions that go to StdOut
  81.     jz    DispOut
  82.     cmp    ah,6
  83.     jz    DirectOut
  84.     cmp    ah,9
  85.     jz    StringOut
  86.     cmp    ah,40h        ;Or maybe to StdErr
  87.     jz    BlockOut
  88.     ToDos
  89.  
  90. ;-----------
  91. DispOut:            ;DOS function 2
  92.     push    ax
  93.     mov     al,dl        ;Character to write in AL
  94.     call    WriteChar    ;Write via video BIOS
  95.     pop     ax
  96.     ToApp            ;Return successfully
  97.  
  98. ;-----------
  99. DirectOut:            ;DOS function 6
  100.     cmp     dl,0FFh        ;Console input?
  101.     jnz     DispOut        ;Jump if not
  102.     ToDos            ;Else transfer to DOS
  103.  
  104. ;------------
  105. StringOut:            ;DOS function 9
  106.     push    ax        ;Save AX
  107.     push    bx        ;Save string index
  108.     mov     bx,dx        ;DS:BX -> string
  109. StringOut1:
  110.     mov     al,[bx]        ;AL = next character to write
  111.     cmp     al,'$'        ;Terminator?
  112.     jz      StringOut2    ;Exit if so
  113.     call    WriteChar    ;Write it
  114.     inc     bx        ;Next character
  115.     jmp     StringOut1    ;Loop
  116. StringOut2:
  117.     pop     bx
  118.     pop     ax
  119.     ToApp            ;Back to application
  120.  
  121. ;------------
  122. BlockOut:            ;DOS function 40h
  123.     cmp     bx,1        ;To StdOut?
  124.     jz      BlockOut1    ;Jump if so
  125.     cmp     bx,2        ;To StdErr?
  126.     jz      BlockOut1    ;Jump if so
  127.     ToDos            ;Else let DOS handle it
  128. BlockOut1:
  129.     jcxz    BlockOut3    ;Get out if none to write
  130.     push    ax
  131.     push    bx
  132.     push    cx        ;Save loop counter
  133.     mov     bx,dx        ;DS:BX -> stuff to write
  134. BlockOut2:
  135.     mov     al,[bx]        ;Next character to write
  136.     call    WriteChar    ;Write it
  137.     inc     bx        ;Next index
  138.     loop    BlockOut2    ;Loop for all the characters
  139.     pop     cx
  140.     pop     bx
  141.     pop     ax
  142.     mov     ax,cx        ;Wrote all the characters
  143. BlockOut3:
  144.     ToApp            ;Back to application
  145.  
  146. _doswdw    endp
  147.  
  148. ;------------
  149. ; Write a character to current position via BIOS
  150. ; Entry: AL is character to write
  151. ; Must preserve all but AX
  152. WriteChar  proc    near
  153.     push    bp        ;some versions of int 10 BIOS trash BP
  154.     push    bx
  155.     push    cx
  156.     push    dx
  157.     push    ds
  158.  
  159.     mov     bx,DGROUP    ;set up ds
  160.     mov     ds,bx
  161.  
  162.     cmp     al,7        ;Bell character?
  163.     jz      BiosWriteDone    ;Don't write
  164.  
  165.     mov     dx,_wdwpos    ;Current cursor pos in DX
  166.  
  167.     cmp     al,8        ;Backspace?
  168.     jz      BackSpace
  169.     cmp     al,9        ;Tab?
  170.     jz      Tab
  171.     cmp     al,10        ;Line feed?
  172.     jz      LineFeed
  173.     cmp     al,13        ;Carriage return?
  174.     jz      Carriage
  175.  
  176.     call    WriteOne    ;Write one normal character
  177.  
  178. BiosSetCursor:            ;Position cursor
  179.     xor     bh,bh
  180.     mov     ah,2
  181.     int     10h
  182.     mov     _wdwpos,dx    ;Save new cursor position
  183.  
  184. BiosWriteDone:
  185.     pop     ds
  186.     pop     dx
  187.     pop     cx
  188.     pop     bx
  189.     pop     bp
  190.     ret
  191.  
  192. Carriage:
  193.     mov     dl,_wdwupr.col    ;Move to left edge
  194.     jmp     BiosSetCursor
  195.  
  196. LineFeed:  
  197.     cmp     dh,_wdwlwr.row    ;Room to increment row?
  198.     jb      LineFeed1
  199.     mov    al,rowlmt    ;Test if pausing on pages
  200.     cmp    al,0
  201.     jz    GoSrll        ;No, then skip pausing
  202.     jmp    Pause        ;Test if rowcnt forces pausing
  203.  
  204. GoSrll:    mov     ax,0601h    ;Scroll up one line
  205.     mov     cx,_wdwupr
  206.     mov     dx,_wdwlwr
  207.     mov     bh,_wdwattr
  208.     int     10h
  209.     jmp     BiosWriteDone
  210.  
  211. LineFeed1: 
  212.     inc     dh        ;Increment row
  213.     inc    cs:rowcnt    ;Keep track of rows
  214.     jmp    BiosSetCursor    ;No, go set cursor position
  215.  
  216. Tab:    mov    cl,dl
  217.     sub     cl,_wdwupr.Col    ;Characters beyond left edge
  218.     add     cl,8
  219.     and     cl,0F8h        ;To next tab stop
  220.     add     cl,_wdwupr.Col  ;Window coords
  221.     sub     cl,dl        ;Spaces to write
  222.     xor     ch,ch        ;CX = spaces to write
  223.  
  224. Tab1:    mov     al,20h        ;Write spaces
  225.     push    cx
  226.     call    WriteOne    ;One at a time
  227.     xor     bh,bh
  228.     mov     ah,2
  229.     int     10h
  230.     mov     _wdwpos,dx    ;Save new cursor position
  231.     pop     cx
  232.     loop    Tab1        ;Do all of them
  233.     jmp     BiosWriteDone
  234.  
  235. BackSpace: 
  236.     cmp     dl,_wdwupr.col    ;Beyond left edge?
  237.     jbe     BiosWriteDone    ;Exit if not
  238.     dec     dl        ;One left
  239.     xor     bh,bh
  240.     mov     ah,2        ;Position cursor
  241.     int     10h
  242.     mov     _wdwpos,dx
  243.     mov     cx,1        ;Write character
  244.     mov     bl,_wdwattr
  245.     mov     ax,0920h    ;Write a space
  246.     int     10h
  247.     jmp     BiosWriteDone    ;Done now
  248.  
  249. Pause:    mov    al,rowcnt    ;Calculate # of rows processed
  250.     inc    al
  251.     mov    rowcnt,al
  252.     cmp    al,rowlmt    ;Compare against limit
  253.     jae    GetKey        ;Yes, then wait for keystroke
  254.     jmp    GoSrll        ;No, then go scroll page
  255.  
  256. GetKey:    mov    ax,0        ;Zero count
  257.     mov    rowcnt,al    ;Save it
  258.     int    16h        ;Wait for keystroke
  259.     jmp     GoSrll        ;Scroll page
  260.  
  261. WriteChar  endp
  262.  
  263. ;---------------
  264. ; Write one character and update cursor variable
  265. WriteOne   proc    near
  266.     mov     cx,1        ;Write character
  267.     mov     bl,_wdwattr
  268.     xor     bh,bh
  269.     mov     ah,9
  270.     int     10h
  271.  
  272.     cmp     dl,_wdwlwr.col    ;Below right border?
  273.     jb      IncCol         ;If so, just increment column
  274.     cmp     dh,_wdwlwr.row    ;Room for CR/LF?
  275.     jb      IncRow        ;Jump if so
  276.  
  277.     mov     ax,0601h    ;Scroll up one line
  278.     mov     cx,_wdwupr
  279.     mov     dx,_wdwlwr
  280.     mov     bh,_wdwattr
  281.     int     10h
  282.     dec     dh        ;Compensate for inc to follow
  283.  
  284. IncRow:    inc     dh        ;Next row
  285.     mov     dl,_wdwupr.col  ;First col
  286.     dec     dl        ;Compensate for inc to follow
  287.  
  288. IncCol:    inc     dl        ;Increment column
  289.     ret
  290. WriteOne   endp
  291.  
  292. DOSWDW_TEXT    ends
  293.     end
  294.